/*************************************************
 * Filename: bet5.js
 * 这程式最後会送出，范例如以下值
 * [type] => 8              //下注类别
 * [num1] => 7,19,31,43     //号码组合，如果是连碰状态就只有num1
 * [num2] => 4,14,24,34,44  //号码组合
 * [betUnionNum] => 20      //组合单数
 *************************************************/
/**属性*******************************************/
var defaultBetType = 8;   //预设下注类别为 无
var defaultMultiType = 0;  //预设对碰类别为连碰

var currentBetType = defaultBetType;      //目前的下注类别
var currentMultiType = defaultMultiType;  //目前的对碰类别
// var currentOneBetMoney = new Number(); //目前下注金额

var chosenNum = [];      //已选择的号码，如果是胆托则只存非胆拖的值
var chosenMultiNum = []; //已选择的胆托号码
var chosenTwelveAnimal = [Number.NaN, Number.NaN]; //已选择的十二生肖
var chosenUnitMap = [Number.NaN, Number.NaN];      //已选择的尾数
var chosenMixMap = [Number.NaN, Number.NaN];       //已选择的混合对碰

var betUnion = [];                 //下注组合
var betUnionLength = new Number(); //下注组合数，单数

//var TwelveAnimalSeed = 3; //切换生肖阵列本命年的种子，1->鼠(2008)以此类推，修改此种子便可以得到不同结果的TwelveAnimalArray

var TwelveAnimals = ['','鼠','牛','虎','兔','龙','蛇','马','羊','猴','鸡','狗','猪']; //用来储存生肖字串，索引0空出来，从1开始
var TwelveAnimalArray = new Array(13); //描述12生肖各自所代表的数值阵列，在选项启动时才初始它的值，索引0空出来，从1开始
var UnitMapArray = new Array(10);      //描述尾数各自所代表的数值阵列，在选项启动时才初始它的值

/*******************************************属性**/
/**ctrl 选项控制*********************************/
//下注类别  Todo清空演算後展开的资料
function ctrlBetType(ctrlVal){
    ctrlVal = parseInt(ctrlVal);
    switch(ctrlVal){
        case 8:   //三全中
        case 9:   //三中二A
        case 33:  //三中二B
            switchBlockDisplay("notInThreeStar", 0);//关闭生肖、尾数
            switchBlockDisplay("notInThreeStar2", 1);//打开胆拖
        break;
        case 29: //五不中
            switchBlockDisplay("notInThreeStar", 0);//关闭生肖、尾数
            switchBlockDisplay("notInThreeStar2", 0);//关闭胆拖
        break;
        case 7:  //二全中
        case 10: //二中特A
        case 32: //二中特B
        case 11: //特串
            switchBlockDisplay("notInThreeStar", 1);//打开生肖、尾数
            switchBlockDisplay("notInThreeStar2", 1);//打开胆拖
        break;
    }
    if(currentMultiType == 0 || currentMultiType == 1){
        clearChecked('ballNum');//避免0、1之前切换前有留资料，先清除一次
    }
    // 针对5不中特别秀赔率 2011.01.27
    if(ctrlVal == 29){ _showBet29Rate(true,29); }
    else if(ctrlVal == 8){ _showBet29Rate(true,8); }
    else{ _showBet29Rate(false,0); }

    currentBetType = ctrlVal;//目前的下注类别
    clearRecord();//清除纪录
}

//对碰类别  Todo清空演算後展开的资料
function ctrlMultiType(ctrlVal){
    ctrlVal = parseInt(ctrlVal);
    
    switch(ctrlVal){
        case 0://连碰
        case 1://胆拖
            switchBlockDisplay("numBlock", 1);//开启号码区块
            switchBlockDisplay("twelveAnimalBlock", 0);
            switchBlockDisplay("unitMapBlock", 0);
            switchBlockDisplay("mixMapBlock", 0);
            clearChecked('ballNum');//避免0、1之前切换前有留资料，先清除一次
        break;
        
        case 2://生肖对碰
            switchBlockDisplay("twelveAnimalBlock", 1);//开启生肖区块
            switchBlockDisplay("numBlock", 0);
            switchBlockDisplay("unitMapBlock", 0);
            switchBlockDisplay("mixMapBlock", 0);
            _initalizeProperty("TwelveAnimalArray");//初始化生肖变数
        break;
        
        case 3://尾数对碰
            switchBlockDisplay("unitMapBlock", 1);//开启尾数区块
            switchBlockDisplay("numBlock", 0);
            switchBlockDisplay("twelveAnimalBlock", 0);
            switchBlockDisplay("mixMapBlock", 0);
            _initalizeProperty("UnitMapArray");//初始化尾数变数
        break;
        
        case 4://混合对碰
            switchBlockDisplay("mixMapBlock", 1);//开启混合区块
            switchBlockDisplay("numBlock", 0);
            switchBlockDisplay("unitMapBlock", 0);
            switchBlockDisplay("twelveAnimalBlock", 0);
            _initalizeProperty("TwelveAnimalArray");//初始化生肖变数
            _initalizeProperty("UnitMapArray");//初始化尾数变数
        break;
    }
    currentMultiType = ctrlVal;//目前的对碰类别
    clearRecord();//清除纪录
}

//号码
function ctrlNum(ctrl){
    var ctrlValue = parseInt(ctrl.value);
    if(currentMultiType == 0){//连碰
        if(ctrl.checked == true){//选取
            chosenNum.push(ctrlValue);//新增
        }else{//选消
            chosenNum = _arrayRemove(chosenNum, ctrlValue);
        }
        chosenNum = _arraySort(chosenNum);//已选择的号码重新排列
        computeUnion();//计算组合
    
    
    }else if(currentMultiType == 1){//胆拖
        if(currentBetType != 29){//无胆拖
			if(currentBetType == 7 || currentBetType == 10 || currentBetType == 11 || currentBetType == 32){ //1胆
				if(chosenMultiNum.length < 1){
					chosenMultiNum.push(ctrlValue);//新增
					ctrl.disabled = true;
					displayMultiMap();//输出胆状态
				}else{
					if(ctrl.checked == true){//选取
						chosenNum.push(ctrlValue);//新增
					}else{//选消
						chosenNum = _arrayRemove(chosenNum, ctrlValue);//移除
					}
				}
			}else{//2胆
				if(chosenMultiNum.length < 2){
					chosenMultiNum.push(ctrlValue);//新增
					ctrl.disabled = true;
					displayMultiMap();//输出胆状态
				}else{
					if(ctrl.checked == true){//选取
						chosenNum.push(ctrlValue);//新增
					}else{//选消
						chosenNum = _arrayRemove(chosenNum, ctrlValue);//移除
					}
				}
				chosenMultiNum = _arraySort(chosenMultiNum);//重新排列
			}
			chosenNum = _arraySort(chosenNum);//已选择的号码重新排列
			computeUnion();//计算组合
		}
    }

}

//生肖
function ctrlTwelveAnimal(ctrl){
    var currentIdx = (ctrl.name == 'twleveAnimals[0]') ? 0:1;//目前点选的索引值
    var compareIdx = (currentIdx == 0) ?1:0;//用来比较的索引值
    //判断两选项值是否相同，相同者取消点选，不同者写入chosenTwelveAnimal
    if(chosenTwelveAnimal[compareIdx] && (ctrl.value == chosenTwelveAnimal[compareIdx])){
        chosenTwelveAnimal[currentIdx] = Number.NaN;
        ctrl.checked = false;
    }else{
        chosenTwelveAnimal[currentIdx] = new Number();
        chosenTwelveAnimal[currentIdx] = ctrl.value;
    }
    computeUnion();//计算组合
}

//尾数
function ctrlUnitMap(ctrl){
    var currentIdx = (ctrl.name == 'unitMap[0]') ? 0:1;//目前点选的索引值
    var compareIdx = (currentIdx == 0) ?1:0;//用来比较的索引值
    //判断两选项值是否相同，相同者取消点选，不同者写入chosenUnitMap
    if(chosenUnitMap[compareIdx] && (ctrl.value == chosenUnitMap[compareIdx])){
        chosenUnitMap[currentIdx] = Number.NaN;
        ctrl.checked = false;
    }else{
        chosenUnitMap[currentIdx] = new Number();
        chosenUnitMap[currentIdx] = ctrl.value;
    }
    computeUnion();//计算组合
}
//混合
function ctrlMixMap(ctrl){
    var currentIdx = (ctrl.name == 'mixMap[0]') ? 0:1;//目前点选的索引值
    chosenMixMap[currentIdx] = new Number();
    chosenMixMap[currentIdx] = ctrl.value;
    computeUnion();//计算组合
}

//送出前检查表单
function chkForm(frm){
    //检查下注栏位
	if (currentBetType<7 || (currentBetType>11 && (currentBetType<29 || currentBetType>33))) {
		alert('请先选择类别');
		return false;
	}
	switch(currentMultiType){
		case 0://连碰，To Do检查还可以再细一点
			if(chosenNum < 1){
				alert('号码未选择');
				return false;
			}
			if (currentBetType == 29) {
				betUnionLength = chosenNum.length;//组合数
				if(betUnionLength > 5){
					alert('五不中只能选择5组号码');
					return false;
				}
			}
		break;
        
		case 1://胆拖，To Do检查还可以再细一点
			if (currentBetType == 29) {
				alert('五不中只能选择连碰方式下注');
				return false;
			} else if(chosenNum < 1){
				alert('号码未选择');
				return false;
			}
		break;
        
		case 2://生肖对碰
			for(var i=0; i < chosenTwelveAnimal.length; i++){
				if(isNaN(chosenTwelveAnimal[i])){
					alert('生肖'+(i+1)+'未选择');
					return false;
					break;
				}
			}
		break;
        
		case 3://尾数对碰
			for(var i=0; i < chosenUnitMap.length; i++){
				if(isNaN(chosenUnitMap[i])){
					alert('尾数'+(i+1)+'未选择');
					return false;
					break;
				}
			}
		break;
        
		case 4://混合对碰
			for(var i=0; i < chosenMixMap.length; i++){
				if(isNaN(chosenMixMap[i])){
					alert('选项'+(i+1)+'未选择');
				return false;
					break;
				}
			}
		break;
	}
    /* /检查注金栏位
    if(currentOneBetMoney < 1){
        alert('金额未输入');
        return false;
    }
	*/
    frm.submit();

}
/*********************************ctrl 选项控制**/


/**显示及作用控制*********************************/
//区块显示控制
function switchBlockDisplay(blockId, isDisplay){
    var targetBlock = document.getElementById(blockId);
    if(isDisplay == 1){
        if(targetBlock.style.display != "block") targetBlock.style.display = "block";
        //enable控制项
    }else{
        if(targetBlock.style.display != "none") targetBlock.style.display = "none";
        //disable控制项
        switch(blockId){
            case "notInThreeStar"://隐藏生肖、尾数时，如果选项正在生肖、尾数上回到预设
                var radioGroup = document.forms["betForm"]["multiType"];
                if(radioGroup[2].checked == true || radioGroup[3].checked == true || radioGroup[4].checked == true){
                    if(radioGroup[2].checked == true) radioGroup[2].checked = false; 
                    if(radioGroup[3].checked == true) radioGroup[3].checked = false;
                    if(radioGroup[4].checked == true) radioGroup[4].checked = false;
                    radioGroup[0].checked = true;
                    ctrlBetType(defaultBetType);
                    ctrlMultiType(defaultMultiType);
                }
            break;
            case "notInThreeStar2"://隐藏生肖、尾数、胆拖时，如果选项正在生肖、尾数、胆拖上回到预设
                var radioGroup = document.forms["betForm"]["multiType"];
                if(radioGroup[1].checked == true ||radioGroup[2].checked == true || radioGroup[3].checked == true || radioGroup[4].checked == true){
                    if(radioGroup[1].checked == true) radioGroup[1].checked = false;
                    if(radioGroup[2].checked == true) radioGroup[2].checked = false; 
                    if(radioGroup[3].checked == true) radioGroup[3].checked = false;
                    if(radioGroup[4].checked == true) radioGroup[4].checked = false;
                    radioGroup[0].checked = true;
                    ctrlBetType(defaultBetType);
                    ctrlMultiType(defaultMultiType);
                }
            break;
            case "numBlock"://号码区块
                clearChecked('ballNum');
            break;
            
            case "twelveAnimalBlock"://生肖区块
                clearChecked('twleveAnimals[0]');
                clearChecked('twleveAnimals[1]');
            break;
            
            case "unitMapBlock"://尾数区块
                clearChecked('unitMap[0]');
                clearChecked('unitMap[1]');
            break;
            
            case "mixMapBlock"://混合区块
                clearChecked('mixMap[0]');
                clearChecked('mixMap[1]');
            break;
        }
    }
}
//显示胆拖状态
function displayMultiMap(){
    if(chosenMultiNum.length > 0){
        for(var i=0; i < chosenMultiNum.length;i++){
            var targetCaption = document.getElementById('multiMapCap['+i+']');
            var targetValue = document.getElementById('multiMapVal['+i+']');
            targetCaption.innerHTML =(chosenMultiNum.length > 1)? '胆'+ (i+1) +':' : '胆';
            targetValue.innerHTML = chosenMultiNum[i];
        }
    }
}
//清除显示胆拖状态
function clearDisplayMultiMap(){
    for(var i=0; i < 2;i++){
        var targetCaption = document.getElementById('multiMapCap['+i+']');
        var targetValue = document.getElementById('multiMapVal['+i+']');
        targetCaption.innerHTML = '&nbsp;';
        targetValue.innerHTML = '&nbsp;';
    }

}
//显示下注状态讯息
function displayBetStatus(statusMessage){
    document.getElementById("betStatus").innerHTML = statusMessage;
}

//清除 checked group
function clearChecked(groupName){
    var targetGroup = document.forms["betForm"][groupName];
    for (var i = 0; i < targetGroup.length; i++){
        if (targetGroup[i].checked == true){
            targetGroup[i].checked = false;
        }
        if (targetGroup[i].disabled == true){
            targetGroup[i].disabled = false;
        }
    }
}

//清除纪录
function clearRecord(){
    chosenNum = [];//已选择的号码，如果是胆托则只存非胆拖的值
    chosenMultiNum = [];//已选择的胆托号码
    chosenTwelveAnimal = [Number.NaN, Number.NaN];//已选择的十二生肖
    chosenUnitMap = [Number.NaN, Number.NaN];//已选择的尾数
    chosenMixMap = [Number.NaN, Number.NaN];//
    betUnion = [];//下注组合
    betUnionLength = [];//下注组合数
    clearBetUnionValue();//清除组合隐藏栏位值
    displayBetStatus('');//清除下注状态讯息
    clearDisplayMultiMap();//清除显示胆拖状态
}
//清除表单
function clearForm(){
    //依目前所处状态清除内容，包含下注金额也须删除
    switch(currentMultiType){
        case 0://号码区块
        case 1:
            clearChecked('ballNum');
        break;
        case 2://生肖区块
            clearChecked('twleveAnimals[0]');
            clearChecked('twleveAnimals[1]');
        break;
        case 3://尾数区块
            clearChecked('unitMap[0]');
            clearChecked('unitMap[1]');
        break;
        case 4://混合区块
            clearChecked('mixMap[0]');
            clearChecked('mixMap[1]');
        break;
    }
    // document.getElementById("money").value = "";
    clearRecord();
}
/*********************************显示及作用控制**/

/**产生组合***************************************/
//计算组合
function computeUnion(){
    switch(currentMultiType){
        case 0://连碰
            betUnion = chosenNum;//下注组合取值
			betUnionLength = chosenNum.length;//组合数
			if (currentBetType == 29) {  // 五支号码一组
				var bet_Length = betUnionLength*(betUnionLength-1)*(betUnionLength-2)*(betUnionLength-3)*(betUnionLength-4)/120;//组合数
				if(bet_Length > 0){_disUnchk(true);}else{_disUnchk(false);} // 若勾了1组，就不可再勾
			} else if (currentBetType == 8 || currentBetType == 9 || currentBetType == 33) {  // 三支号码一组
				var bet_Length = betUnionLength*(betUnionLength-1)*(betUnionLength-2)/6;//组合数
			} else {
				var bet_Length = betUnionLength*(betUnionLength-1)/2;
			}
            createBetUnionValue(betUnion, 1, false);//写入隐藏栏位
            //显示状态
            var statusMessage = "[" + betUnion.join(",") + "]，组成"+ bet_Length +"笔";
            displayBetStatus(statusMessage);
        break;
        case 1://胆拖
			if (currentBetType != 29) {
				//胆固定
				betUnionLength = chosenNum.length;//组合数
				betUnion = new Array(2);//初始化为长度2的阵列
				betUnion[0] = chosenMultiNum;
				betUnion[1] = chosenNum;
				createBetUnionValue(betUnion, betUnionLength, true);//写入隐藏栏位
				//显示状态
				var statusMessage = "[" + chosenMultiNum.join(",") + "]";
				if(betUnionLength > 0){
					statusMessage += "[" + chosenNum.join(",") + "]";
					statusMessage += "，组成"+ betUnionLength +"笔";
				}
				displayBetStatus(statusMessage);
			}
        break;
        
        case 2://生肖对碰chosenTwelveAnimal = [null, null];
            //产生组合
            betUnionLength = (!isNaN(chosenTwelveAnimal[0]) && !isNaN(chosenTwelveAnimal[1])) ? (TwelveAnimalArray[chosenTwelveAnimal[0]].length*TwelveAnimalArray[chosenTwelveAnimal[1]].length) : 0;//组合数
            betUnion = new Array(2);//初始化为长度2的阵列
            if(!isNaN(chosenTwelveAnimal[0])) betUnion[0] = TwelveAnimalArray[chosenTwelveAnimal[0]];
            if(!isNaN(chosenTwelveAnimal[1])) betUnion[1] = TwelveAnimalArray[chosenTwelveAnimal[1]];
            if(!isNaN(chosenTwelveAnimal[0]) && !isNaN(chosenTwelveAnimal[1])) createBetUnionValue(betUnion, betUnionLength, true);//写入隐藏栏位
            //显示状态
            var statusMessage = '';
            if(!isNaN(chosenTwelveAnimal[0])){
                statusMessage += TwelveAnimals[chosenTwelveAnimal[0]] + "[" + betUnion[0].join(",") + "]";
                if(!isNaN(chosenTwelveAnimal[1])){
                    statusMessage += " 碰 "+TwelveAnimals[chosenTwelveAnimal[1]] + "["+ betUnion[1].join(",") +"]，组成"+ betUnionLength +"笔";
                }
            }
            displayBetStatus(statusMessage);

        break;
        
        case 3://尾数对碰var chosenUnitMap = [null, null];
            //产生组合
            betUnionLength = (!isNaN(chosenUnitMap[0]) && !isNaN(chosenUnitMap[1])) ? (UnitMapArray[chosenUnitMap[0]].length * UnitMapArray[chosenUnitMap[1]].length) : 0;//组合数
            betUnion = new Array(2);//初始化为长度2的阵列
            if(!isNaN(chosenUnitMap[0])) betUnion[0] = UnitMapArray[chosenUnitMap[0]];
            if(!isNaN(chosenUnitMap[1])) betUnion[1] = UnitMapArray[chosenUnitMap[1]];
            if(!isNaN(chosenUnitMap[0]) && !isNaN(chosenUnitMap[1])) createBetUnionValue(betUnion, betUnionLength, true);//写入隐藏栏位
            //显示状态
            var statusMessage = '';
            if(!isNaN(chosenUnitMap[0])){
                statusMessage += chosenUnitMap[0] + "尾[" + betUnion[0].join(",") + "]";
                if(!isNaN(chosenUnitMap[1])){
                    statusMessage += " 碰 "+ chosenUnitMap[1] + "尾["+ betUnion[1].join(",") +"]，组成"+ betUnionLength +"笔";
                }
            }
            displayBetStatus(statusMessage);
        break;
        
        case 4://混合对碰var chosenMixMap = [null, null];
            //产生组合
            betUnionLength = 0;
            //计算组合数，重复者数量扣除
            if(!isNaN(chosenMixMap[0]) && !isNaN(chosenMixMap[1])){
                var tmpTwelveAnimalNum = TwelveAnimalArray[chosenMixMap[0]].length;
                var tmpUnitMapNum = UnitMapArray[chosenMixMap[1]].length;
                
                for(var i =0; i < TwelveAnimalArray[chosenMixMap[0]].length; i++){
                    for(var j =0; j < UnitMapArray[chosenMixMap[1]].length; j++){
                        if(TwelveAnimalArray[chosenMixMap[0]][i] == UnitMapArray[chosenMixMap[1]][j]){
                            continue;
                        }else{
                            betUnionLength ++;
                        }
                    }
                }
            }
            betUnion = new Array(2);//初始化为长度2的阵列
            if(!isNaN(chosenMixMap[0])) betUnion[0] = TwelveAnimalArray[chosenMixMap[0]];
            if(!isNaN(chosenMixMap[1])) betUnion[1] = UnitMapArray[chosenMixMap[1]];
            if(!isNaN(chosenMixMap[0]) && !isNaN(chosenMixMap[1])) createBetUnionValue(betUnion, betUnionLength, true);//写入隐藏栏位
            //显示状态
            var statusMessage = '';
            if(!isNaN(chosenMixMap[0])){
                statusMessage += TwelveAnimals[chosenMixMap[0]] + "[" + betUnion[0].join(",") + "]";
                if(!isNaN(chosenMixMap[1])){
                    statusMessage += " 碰 "+ chosenMixMap[1] + "尾["+ betUnion[1].join(",") +"]，组成"+ betUnionLength +"笔";
                }
            }
            displayBetStatus(statusMessage);
        break;

    }
}

//赋予组合隐藏栏位值
function createBetUnionValue(valueArray, betNum, isMultiDimen){
    var targetBlock = document.getElementById("betUnionBlock");
    //先清空
    clearBetUnionValue();
    //开始写入组合
    if(isMultiDimen == false){ //一维阵列
        betNum = 1;
        var hiddenItem = document.createElement("input");
        hiddenItem.setAttribute("id", 'num1');
        hiddenItem.setAttribute("name", 'num1');
        hiddenItem.setAttribute("type","hidden");
        hiddenItem.setAttribute("value", valueArray.join(","));
        targetBlock.appendChild(hiddenItem);
    }else{
        //写入各选项的组合
        for(var i=0;i < valueArray.length; i++){
            var hiddenItem = document.createElement("input");
            hiddenItem.setAttribute("id", 'num'+(i+1));
            hiddenItem.setAttribute("name", 'num'+(i+1));
            hiddenItem.setAttribute("type","hidden");
            hiddenItem.setAttribute("value", valueArray[i].join(","));
            targetBlock.appendChild(hiddenItem);
        } 
    }
    //下注组合数，单数
    var hiddenBetUnionNum = document.createElement("input");
    hiddenBetUnionNum.setAttribute("id", 'betUnionNum');
    hiddenBetUnionNum.setAttribute("name", 'betUnionNum');
    hiddenBetUnionNum.setAttribute("type","hidden");
    hiddenBetUnionNum.setAttribute("value", betNum);
    targetBlock.appendChild(hiddenBetUnionNum);
}

//清除组合隐藏栏位值
function clearBetUnionValue(){
    var targetBlock = document.getElementById("betUnionBlock");
    targetBlock.innerHTML ='';
}
/***************************************产生组合**/
/**工具函式***************************************/
//初始化属性
function _initalizeProperty(propertyName){
    if(propertyName == "TwelveAnimalArray"){
        //基本对应阵列
		tmpTwelveAnimalArray = [null,
		[1,13,25,37,49],   //1
		[2,14,26,38],      //2
		[3,15,27,39],      //3
		[4,16,28,40],      //4
		[5,17,29,41],      //5
		[6,18,30,42],      //6
		[7,19,31,43],      //7
		[8,20,32,44],      //8
		[9,21,33,45],      //9
		[10,22,34,46],     //10
		[11,23,35,47],     //11
		[12,24,36,48]];    //12

        var mapingArray = new Array();//用来存放对应的阵列
        for(var i=1;i <= 12;i++){
            if(i == TwelveAnimalSeed){//等於种子者为1
                mapingArray[i] = 1;
            }else if(i < TwelveAnimalSeed){//小於种子的
                mapingArray[i] = (TwelveAnimalSeed - i)+1;
            }else{//大於种子的
                var tmpLoopNum = i-TwelveAnimalSeed;
                var tmpCunt = 0;
                for(var j=12;j >=1 ;j--){
                    tmpCunt++;
                    if(tmpCunt == tmpLoopNum){
                        mapingArray[i] = j;
                        break;
                    }
                }
            }
        }
        //开始初始TwelveAnimalArray阵列
        for(var i=1;i <= 12;i++){
            TwelveAnimalArray[i] = tmpTwelveAnimalArray[mapingArray[i]];
        }
    }else if(propertyName == "UnitMapArray"){
        UnitMapArray =[ 
        [10,20,30,40],
        [1,11,21,31,41],
        [2,12,22,32,42],
        [3,13,23,33,43],
        [4,14,24,34,44],
        [5,15,25,35,45],
        [6,16,26,36,46],
        [7,17,27,37,47],
        [8,18,28,38,48],
        [9,19,29,39,49]      
        ];
    }
    
    
}
//取得选项的值
function _getRadioValueByName(groupName){
    var targetGroup = document.forms["betForm"][groupName];
    var returnValue = new Number(); 
    for (var i = 0; i < targetGroup.length; i++){
        if (targetGroup[i].checked == true){
            returnValue = targetGroup[i].value;
        }
    }
    return returnValue;
}
//阵列排序
function _arraySort(sortArray){
    arrayLength = sortArray.length;
    for (var i = 0; i < arrayLength; i++) {
        var arrayValue = sortArray[i];
        for (var j = i - 1; ( (j >= 0) && (sortArray[j] > arrayValue) ); j--) {
            sortArray[j + 1] = sortArray[j];
        }
        sortArray[j + 1] = arrayValue;
    }
    return sortArray;
}

//阵列remove
function _arrayRemove(removeArray, removeKey){
    var tmpArray = new Array();
    for(var i=0; i < removeArray.length; i ++){
        if(removeArray[i] != removeKey){
            tmpArray.push(removeArray[i]);
        }
    }
    return tmpArray;
}

// -----------------------------------------------------------------------------
// 显示 class 为 bet29Rate 的资料
// @param boolean bShow : true 显示, false 隐藏
// -----------------------------------------------------------------------------
function _showBet29Rate(bShow,idx){     
  oTal = document.getElementById("numBlock");
  if(bShow == false){
    for(var i=0; i < oTal.rows.length; i++){
      for( var j=0; j < oTal.rows[i].cells.length; j++){
        if(oTal.rows[i].cells[j].className == 'bet29Rate'){oTal.rows[i].cells[j].className = 'bet29RateOff';}
      }
    }
  }else{
    for(var i=0; i < oTal.rows.length; i++){
      for( var j=0; j < oTal.rows[i].cells.length; j++){
        if(oTal.rows[i].cells[j].className == 'bet29RateOff' || oTal.rows[i].cells[j].className == 'bet29Rate'){
          oTal.rows[i].cells[j].className = 'bet29Rate';
          obj = oTal.rows[i].cells[j].getElementsByTagName("span");
          if (obj.length>0){//span is found.
            switch(idx){
              case 8:
                obj[0].className = 'disNone';
                obj[1].className = '';
                break;            
              case 29:
                obj[1].className = 'disNone';
                obj[0].className = '';
                break;
            }
          }
        }
      }
    }
  }
}

// -----------------------------------------------------------------------------
// 是否把 未打勾的 checkbox 设为 disabled
// @param boolean bDis : true 把未勾选的设disabled, false 把全部设为可勾选  
// -----------------------------------------------------------------------------
function _disUnchk(bDis){
  var oChkStr = "";
  var oChk = "";
  if(bDis == false){
    for(var i=1; i < 50; i++){
      oChkStr = "ballNum[" + i + "]";
      document.getElementById(oChkStr).disabled = false;
    }
  }else{
    for(var i=1; i < 50; i++){
      oChkStr = "ballNum[" + i + "]";
      if(document.getElementById(oChkStr).checked == false){
        document.getElementById(oChkStr).disabled = true;
      }else{
        document.getElementById(oChkStr).disabled = false;
      }
    }

  }

}
/***************************************工具函式**/
function nowdate()
{
    document.all.hktime.innerHTML = "现在 <b>"+now.getDate()+"</b> 日 <b>"+d2(now.getHours())+" : "+d2(now.getMinutes())+" : "+d2(now.getSeconds())+"</b>";
    now.setTime(now.getTime() + 1000);
    setTimeout("nowdate()",1000);
}

function countdown()
{
  timediff = timestap;
  days = Math.floor(timediff / (60 * 60 * 24));
	timediff -= days * (60 * 60 * 24);
	hours = Math.floor(timediff / (60 * 60));
	timediff -= hours * (60 * 60);
	mins = Math.floor(timediff / (60));
	timediff -= mins * (60);
	secs = Math.floor(timediff);

    str = "离截止下注 ";
    if (days > 0 ) str += "<b>" + days + "</b> 天 ";
    if (hours > 0) str += "<b>" + hours + "</b> 时 ";  // 
    if (mins > 0) str += "<b>" + d2(mins) + "</b> 分 ";  // 
    str += "<b>" + d2(secs) + "</b> 秒"; //
    countdownstr.innerHTML =  str;
    setTimeout("countdown()",1000)
    timestap-=1;
    if (timestap==0) {
        location.reload();
    }
}
function d2(v)
{
	return (v<=9?'0':'')+v;	
}